Function.RegisterNamespace("System.EnvironmentStrategy.V8");

System.EnvironmentStrategy.V8=function(){
    // IEnvironmentStrategy members
    this.Execute=function(command, parameters,voidOutput){
        var result=os.system(command,parameters);
        if(!voidOutput)return result;
    };

    this.Exit=function(errorCode){
        quit(errorCode);
    };

    this.GetNewLine=function(){
        throw new Error("System.EnvironmentStrategy.SpiderMonkey.GetNewLine: Not Implemented. This method is abstract and must be overridden.");
    };

    this.GetParameters=function(){
        var args={
            named:{},
            unnamed:[]
        };
        var params=Object.Global().arguments;
        for(var i=0;i<params.length;i++){
            var param=String.Trim(params[i]);
            if(String.StartsWith(param,'/')&&String.Contains(param,':')){
                param=String.TrimStart(param,'/').split(':');
                args.named[param[0].toLowerCase()]=param.slice(1).join(':');
            }else args.unnamed.push(param);
        }
        return args;
    };
    
    this.GetWorkingDirectory=function(){
        throw new Error("System.EnvironmentStrategy.SpiderMonkey.GetWorkingDirectory: Not Implemented. This method is abstract and must be overridden.");
    };

    this.Write=function(message1,message2,messageN){
        write.apply(Object.Global(),arguments);
    };
    
    this.WriteError=this.Write;
    
    // IStrategySpecification members
    this.IsSatisfiedBy=function(candidate){
        return (typeof(os)!='undefined' && typeof(os.system)!='undefined');
    };
        
};

System.EnvironmentStrategy.V8.Implement(System.EnvironmentStrategy.IEnvironmentStrategy,'System.EnvironmentStrategy.V8');
System.EnvironmentStrategy.V8.Implement(System.Script.Strategy.IStrategySpecification,'System.EnvironmentStrategy.V8');
